//封装小程序的网络请求
const BASEURL = 'https://www.uinav.com/api/public/v1/'

const request = ({
    url,
    method = "GET",
    data = {},
    header = {},
    tip = '拼命加载中'
}) => {
    return new Promise((resolve,reject) => {
        uni.showLoading({
            title:tip
        })
        uni.request({
            url:`${BASEURL}${url}`,
            method,
            data,
            header, //请求的时候有请求头就带上，没有就不用
            success:res=>{ //请求从的回调
                resolve(res.data)
            },
            fail:err => { //请求失败的回调
                reject(err)
            },
            complete:()=>{
                uni.hideLoading()
            }
        })
    })
}

uni.$request = request